package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.TravelCommend;
import cn.wolfcode.trip.base.domain.TravelComment;
import cn.wolfcode.trip.base.query.SystemMessageQueryObject;
import cn.wolfcode.trip.base.query.TravelCommentQueryObject;
import cn.wolfcode.trip.base.service.ISystemMessageService;
import cn.wolfcode.trip.base.service.ITravelCommendService;
import cn.wolfcode.trip.base.service.ITravelCommentService;
import cn.wolfcode.trip.base.util.JsonResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("travelComments")
public class TravelCommentContoller {
    @Autowired
    private ITravelCommentService travelCommentService;

    /**
     * 获取评论列表
     * @param qo
     * @return
     */
    @GetMapping("/{userId}")
    public PageInfo list(TravelCommentQueryObject qo){
        qo.setOrderBy("tc.createTime asc");
        return travelCommentService.query(qo);
    }
    /**
     * 获取未查看评论条数
     * @param userId
     * @return
     */
    @GetMapping("/nums/{userId}")
    public Object queryForCount(@PathVariable Long userId){
        return travelCommentService.queryForCount(userId);
    }
    /**
     * 修改未查看条数为0
     * @param userId
     * @return
     */
    @PutMapping("/nums/{userId}")
    public JsonResult updateState(@PathVariable Long userId){
        travelCommentService.updateState(userId);
        return new JsonResult();
    }

    @GetMapping("/travel/{travelId}")
    public JsonResult getCommentByTravelId(@PathVariable Long travelId){
        List<TravelComment> list = travelCommentService.getCommentByTravelId(travelId);
        return new JsonResult().setResult(list);
    }

    @PostMapping("/save")
    public JsonResult saveTravelComment(TravelComment travelComment){
        travelCommentService.saveTravelComment(travelComment);
        return new JsonResult();
    }
}
